<?php if (!defined('THINK_PATH')) exit();?><!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<html>
    <head>
        <title>帖子浏览</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel='stylesheet' type='text/css' href='/static/view/css/posts.css'/>
        <link rel='stylesheet' type='text/css' href='/static/view/css/head.css'/>
        <link rel='stylesheet' type='text/css' href='/static/view/css/common.css'/>
        <script type='text/javascript' src='/static/ckeditor/ckeditor.js'></script>
    </head>
    <body>
        
	<div id='head'>
		<div id='head-navi'><a href='http://localhost:8080/index.php' onclick="setHomepage('http://localhost:8080/index.php')">设为首页</a>&nbsp;<b>|</b>&nbsp;<a href='http://localhost:8080/index.php' onclick="alert('请按Ctrl+D添加到收藏夹')">收藏本站</a></div>
		<div id='head-navi-bottom'>
                    <div class='logo'><a href='/User/forum/forum.html' onfocus="this.blur()"><img src='/static/view/image/banner/logo.png'/></a></div>
                    <div class='status'>
                        <?php if(empty($_SESSION['userInfo'])){ echo "<a href='/User/user/login'>登录</a> | "; echo "<a href='/User/user/register'>注册</a>"; }else if($_SESSION['userInfo']['role']=='普通用户'){ echo '欢迎会员<a href='.'/User/user/userInfo?id='.$_SESSION['userInfo']['id'].'>'.$_SESSION['userInfo']['username'].'</a>登录'.'<br/>'.'积分：'.$_SESSION['userInfo']['credits'].'&nbsp;|&nbsp;'.'用户组:'.$_SESSION['userInfo']['role']; echo "      <a href='/User/user/logout/'><input type='button' value='安全退出'></a>"; }else if($_SESSION['userInfo']['role']=='管理员'){ echo '欢迎管理员<a href='.'/User/user/userInfo?id='.$_SESSION['userInfo']['id'].'>'.$_SESSION['userInfo']['username'].'</a>登录'.'<br/>'.'积分：'.$_SESSION['userInfo']['credits'].'&nbsp;|&nbsp;'.'用户组:'.$_SESSION['userInfo']['role']; echo '&nbsp;|&nbsp;<a href="/Admin/user/userList">进入管理中心</a>'; echo "&nbsp;|&nbsp;<a href='/User/user/logout/'><font><b>安全退出</b></font></a>"; } ?>
                    </div>	
            </div>
	</div>
	
	<div id='navi'>
            <ul>
                <li><a href='/User/forum/forum.html'>论坛</a></li>
                <!--<li><a href='/User/user/login.html'>登录</a></li>-->
                <li><a href='/User/user/register.html'>注册</a></li>
                <li><a href='/User/user/findPassword.html'>找回密码</a></li>
                <!--<li><a href='/User/posts/postsList.html'>帖子列表</a></li>-->
                <!--<li><a href='/User/user/searchForum.html'>搜索</a></li>-->
                <!--<li><a href='/User/user/notice.html'>通知</a></li>-->
                <!--<li><a href='/User/forum/aboutUs.html'>关于我们</a></li>-->
                <!--<li><a href="/User/user/logout">安全退出</a></li>-->
            </ul>
	</div>
	<div id='search'>
            <form action='/User/posts/postsSearch' method='post'>
                <label for='search-content'><span style="font-weight:700;">搜索帖子</span></label>
               
                <input id='search-content' class='content' name='theme' type='text' results="n" placeholder='帖子主题' required autocomplete="on" x-webkit-speech speech/>

                <button type='submit'>搜索</button><font style="color:blue;font-weight: 700">　<?php echo '今天是'.date('Y-m-d',time()).'　'.date('D',time()); ?>　<span id="clock"></span></font>
            </form>
	</div>
        <script type='text/javascript' src='/static/view/js/clock.js'></script>
        <script type='text/javascript'>
           startTime();
	$(document).ready(function(){
		/*$('#head-submit').live('click',function(){
                    if($.trim($('#head-username').val())==''||$.trim($('#head-password').val())==''){
                            window.location.href='./login.html';
                    }else{
                        var data=$('#head-form').serialize();
                        $.ajax({
                            url:'./',
                            data:data,
                            dataType:'html',
                            type:'post',
                            success:function(){
                                    $('#head-form').hide();
                                    $('.status').html("<h3>欢迎会员XX登录</h3>");
                            },
                            error:function(){
                                    window.alert('an error accured');
                            }	
                        });
                    }			
		});
		
		$('#head-username').keydown(function(e){
                    if(e.keyCode == 13){
                        e.preventDefault();
                        if($.trim($(this).val()) != ''){
                                $('#head-password').focus();
                        }else{
                                $(this).attr('placeholder','请输入用户名');
                        }
                    }	
		});
		
		$('#head-password').keydown(function(e){
			if(e.keyCode==13){
                            e.preventDefault();
                            if($.trim($(this).val())!=''){
                                    $('#head-submit').trigger('click');
                        }else{
                                $(this).attr('placeholder','请输入密码');
                                //window.location.href='./login.html';
                            }
			}
		});
		
	});*/
	</script>
	

        <p style="font-size:12px;margin: 0px auto 10px 15px;"><a href="/User/forum/forum">论坛</a> &gt; <a href="/User/forum/forumDetail?id=<?php echo ($forum["id"]); ?>"><?php echo ($forum["parent_forum_name"]); ?></a> &gt; <a href="/User/forum/forumDetail?id=<?php echo ($forum["id"]); ?>"><?php echo ($forum["forum_name"]); ?></a> &gt; <?php echo ($posts["theme"]); ?></p>
        <div class='posts-body'>
            <!--主题帖子-->
            <div class="posts-div">
                <div class="author" style="padding-top: 30px;"> 
                    <table border="0px" width="200px" cellpadding="3">
                        <tr align="center"><td colspan="3"><a href="/User/user/userInfo?id=<?php echo ($author["id"]); ?>"><?php echo ($author["username"]); ?></a></td></tr>
                        <tr align="center"><td colspan="3" align="center"><img src="<?php echo ($author["head_img"]); ?>" height="109px"/></td></tr>
                        <tr align="center"><td colspan="3">积分　　　　<?php echo ($author["credits"]); ?></td></tr>
                        <tr align="center"><td colspan="3"><?php echo ($author["role"]); ?></td></tr>
                    </table>
                </div>
                <div class="posts-content">
                    <form action="/User/posts/editPosts" method="post">
                        <h3><?php echo ($posts["theme"]); ?></h3><br/>
                        <div style="border-bottom:1px dashed #BDD7E3"></div><br/>
                        <div style="height: auto;"><?php echo ($posts["author"]); ?> 发表于 <?php echo ($posts["dateline"]); ?> | 跟帖数：<?php echo ($reply_count); ?> | 楼主</div><br/>
                        <div class="content-div" style="height: auto;min-height: 100px">
                            <textarea style="display: none" class="content" name="content" rows="5" cols="50"></textarea>
                            <span class="content-now"><?php echo ($posts["content"]); ?></span><?php if(empty($posts["mood"])): echo ($postsDetail["mood"]); else: ?><img src="<?php echo ($posts["mood"]); ?>"/><?php endif; ?>
                        </div><br/>
                        <input name="posts_id" value="<?php echo ($posts["id"]); ?>" type="hidden"/>
                        <input name="author_id" value="<?php echo ($author["id"]); ?>" type="hidden"/>
                        <input name="forum_id" value="<?php echo ($forum["id"]); ?>" type="hidden"/>
                        <div class="btn-select"><?php if($posts["author"] == $_SESSION['userInfo']['username']): ?><input class="edit" type="button" value="编辑">&nbsp;<a href="#reply">回复</a><?php else: ?><a href="#reply">回复</a><?php endif; ?></div><br/><!--连接到锚点-->
                    </form>
                    <div style="border-bottom:1px dashed #BDD7E3"></div><br/>
                </div>
            </div>
            <!--回复列表-->
            <?php if(is_array($reply)): $i = 0; $__LIST__ = $reply;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$reply): $mod = ($i % 2 );++$i;?><div style="border-bottom:1px solid #BDD7E3"></div>
                <div class="posts-div">
                        <div class="author" style="padding-top: 30px;">
                            <table border="0px" width="200px" cellpadding="3">
                                <tr align="center"><td colspan="3"><a href="/User/user/userInfo?id=<?php echo ($reply["u_id"]); ?>"><?php echo ($reply["username"]); ?></a></td></tr>
                                <tr align="center"><td colspan="3" align="center"><img src="<?php echo ($reply["head_img"]); ?>" height="109px"/></td></tr>
                                <tr align="center"><td colspan="3">积分　　　　<?php echo ($reply["credits"]); ?></td></tr>
                                <tr align="center"><td colspan="3"><?php echo ($reply["role"]); ?></td></tr>
                            </table>
                        </div>
                        <div class="posts-content">
                            <form action="/User/posts/editReply" method="post">
                                <div style="height: auto;"><?php echo ($reply["author"]); ?> 发表于 <?php echo ($reply["dateline"]); ?> | <input readonly name="id" value="<?php echo ($reply["r_id"]); ?>#" style="width: 50px;border: 0"/></div><br/>
                                <div style="border-bottom:1px dashed silver"></div><br/>
                                <input name="posts_id" value="<?php echo ($posts["id"]); ?>" type="hidden"/>
                                <input name="author_id" value="<?php echo ($author["id"]); ?>" type="hidden"/>
                                <input name="forum_id" value="<?php echo ($forum["id"]); ?>" type="hidden"/>
                                <div class="content-div" style="height: auto;min-height: 150px">
                                    <textarea rows="5" cols="50" name="content" style="display: none" class="content"></textarea><span class="content-now" style="display: block"><?php echo ($reply["content"]); ?></span><?php if(empty($reply["mood"])): echo ($reply["mood"]); else: ?><img src="<?php echo ($reply["mood"]); ?>"/><?php endif; ?>
                                </div><br/>
                                <div class="btn-select"><?php if($reply["author"] == $_SESSION['userInfo']['username']): ?><input class="edit" type="button" value="编辑">&nbsp;<a href="#reply">回复</a><?php else: ?><a href="#reply">回复</a><?php endif; ?></div><br/>
                                <div style="border-bottom:1px dashed #BDD7E3"></div><br/>
                            </form>
                        </div>
                </div><?php endforeach; endif; else: echo "" ;endif; ?>
            <div class="posts-div" style="background-color: white;"><div style="height: 35px;width:217px;background-color:#E8F0F7;float: left; "></div><div style="padding-left:10px;float:left;"><?php echo ($page); ?></div></div>
            <!--发表回复-->
            <div style="border-bottom:1px solid #BDD7E3"></div>
            <div class="posts-div">
                <div class="author" style="padding-top: 30px;">
                   <table border="0px" width="200px" cellpadding="3">
                        <tr align="center"><td colspan="3"><?php if($_SESSION['userInfo']){echo '<a href=/User/user/userInfo?id='.$_SESSION['userInfo']['id'].'>'.$_SESSION['userInfo']['username'].'</a>';}else{echo '游客';} ?></td></tr>
                        <tr align="center"><td colspan="3" align="center"><?php if($_SESSION['userInfo']){echo '<img src='.$_SESSION["userInfo"]["head_img"].' height=109px />';}else{echo "<img src='/static/view/image/head-img/default.jpg' height='109px'/>";} ?></td></tr>
                        <tr align="center"><td colspan="3">积分　　　　<?php if($_SESSION['userInfo']){echo $_SESSION['userInfo']['credits'];}else{echo 0;} ?></td></tr>
                        <tr align="center"><td colspan="3"><?php if($_SESSION['userInfo']){echo $_SESSION['userInfo']['role'];}else{echo '游客';} ?></td></tr>
                    </table>
                </div>
                <div class="posts-content"><a name="reply"></a>
                    <form action="/User/posts/submitReply" method="post" id="submit_reply">
                        <h3>发表回复</h3>
                        <div style="margin-top:10px;border: 0px solid silver;border-bottom: 0px;">
                            <input name="mood" type="radio" value="/static/view/image/mood/001.gif"/><img src="/static/view/image/mood/001.gif"/>
                            <input name="mood" type="radio" value="/static/view/image/mood/002.gif"/><img src="/static/view/image/mood/002.gif"/>
                            <input name="mood" type="radio" value="/static/view/image/mood/003.gif"/><img src="/static/view/image/mood/003.gif"/>
                            <input name="mood" type="radio" value="/static/view/image/mood/004.gif"/><img src="/static/view/image/mood/004.gif"/>
                            <input name="mood" type="radio" value="/static/view/image/mood/005.gif"/><img src="/static/view/image/mood/005.gif"/>
                            <input name="mood" type="radio" value="/static/view/image/mood/006.gif"/><img src="/static/view/image/mood/006.gif"/>
                            <input name="mood" type="radio" value="/static/view/image/mood/007.gif"/><img src="/static/view/image/mood/007.gif"/>
                            <input name="mood" type="radio" value="/static/view/image/mood/008.gif"/><img src="/static/view/image/mood/008.gif"/>
                            <input name="mood" type="radio" value="/static/view/image/mood/009.gif"/><img src="/static/view/image/mood/009.gif"/>
                            <input name="mood" type="radio" value="/static/view/image/mood/010.gif"/><img src="/static/view/image/mood/010.gif"/>
                            <input name="mood" type="radio" value="/static/view/image/mood/011.gif"/><img src="/static/view/image/mood/011.gif"/>
                            <input name="mood" type="radio" value="/static/view/image/mood/012.gif"/><img src="/static/view/image/mood/012.gif"/>
                            <input name="mood" type="radio" value="/static/view/image/mood/013.gif"/><img src="/static/view/image/mood/013.gif"/>
                            <span style="float: right;margin-right: 470px;">
                                <input type="button" id="btn_h_type" value="高级模式">
                                <input type="button" id="btn_l_type" value="普通模式" style="display: none">
                            </span>
                        </div>
                        <input name="forum_id" value="<?php echo ($forum["id"]); ?>" type="hidden"/>
                        <input name="theme_id" value="<?php echo ($posts["id"]); ?>" type="hidden"/>
                        <input name="author_id" value="<?php echo ($author["id"]); ?>" type="hidden"/>
                        <span id="btn">
                        <input name="" type="button" value="h1" id="h1" class="btn" title="1号标题"/>
                        <input name="" type="button" value="h2" id="h2" class="btn" title="2号标题"/>
                        <input name="" type="button" value="h3" id="h3" class="btn" title="3号标题"/>
                        <input name="" type="button" value="h4" id="h4" class="btn" title="4号标题"/>
                        <input name="" type="button" value="h5" id="h5" class="btn" title="5号标题"/>
                        <input name="" type="button" value="b" id="bold" class="btn" title="粗体"/>
                        <input name="" type="button" value="i" id="italics" class="btn" title="斜体"/>
                        <input name="" type="button" value="u" id="underline" class="btn" title="下划线"/>
                        <!--<button type="button" id="apply" class="btn-mini btn-danger">apply</button>--><br/>
                        </span>
                        <p>
                        <textarea id="selectable" name="content" cols="84" rows="8" style="border:1px solid #BDD7E3">
                        </textarea>
                        </p>
                        <p id="container"></p>
                        <?php if(!empty($_SESSION['userInfo'])){echo "<button type='submit'>发表回复</button>";}else{echo "您还没登陆，发表回复<a href='/User/user/login'>请登录</a>";} ?>
                    </form>
                </div>
            </div>
    </div>
    <div style="margin:20px 15px;color:#6D6D6D;">
        <div style="border-bottom: 1px solid #BDD7E3"></div>
        <div style="padding:10px 0px;line-height: 1.8;">
                <p>Copyright &copy;2012-2013 shaobo,test</p>
                <p>Welcome to our Bulletin Board System.It is our <strong>beta</strong> version,contact <a href="mailto:shaaoboo@sina.com"><font color='blue'>shaaoboo@sina.com</font></a> to give us your valuable suggestion.</p>
        </div>
</div>

    
    <script type="text/javascript" src="/static/bootstrap/js/bootstrap.js"></script>
    <script type="text/javascript" src="/static/viewback/js/jquery-1.8.3.js"></script>
    <script type="text/javascript">
        function getPositions(){
            var startPosition=endPosition=0;
            var element=document.getElementById('selectable');
            if(document.selection){
                var range=document.selection.createRange();
                var drange=range.duplicate();
                drange.moveToElementText(element);
                drange.setEndPoint('EndToEnd',range);
                startPosition=drange.text.length-range.text.length;
                endPosition=startPosition+range.text.length;alert('ie');
            }
            else if(window.getSelection){
                //firefox chrome safari
                startPosition=element.selectionStart;
                endPosition=element.selectionEnd;//alert(endPosition);
            }
            return {'start':startPosition,'end':endPosition};
        }
        $(document).ready(function(){
             $('#btn_h_type').click(function(){
                CKEDITOR.replace( 'selectable', {
                        uiColor: '#BDD7E3',
                        toolbarCanCollapse:true,
                        language :'zh-cn'
                        //toolbarLocation :''
                });
                $('#btn').css('display','none');
                $('#btn_l_type').css('display','inline');
                $('#btn_h_type').css('display','none');
            });
            $('#btn_l_type').click(function(){
                document.location.reload();
                $('#btn_l_type').css('display','none');
                $('#btn_h_type').css('display','inline');
            });
            /*格式化文本，给文本选中添加样式，例如斜体，粗体*/
            $('#apply').click(function(){
                $('#container').html($('#selectable').val());
            });
            $('.btn').click(function(){
                var positions=getPositions();
                if(positions.start==positions.end){
                    return false;
                }
                var tag=$(this).val();
                var textOnPage=$('#selectable').val();
                var startString=textOnPage.substr(0, positions.start);
                var targetString=textOnPage.substr(positions.start,positions.end-positions.start);
                var formattedString="<" + tag+">" + targetString + "</"+tag+">";
                var endString=textOnPage.substr(positions.end);//alert(endString+'||'+startString+'||'+formattedString);
                $("#selectable").val(startString + formattedString + endString);//alert($("#selectable").val());
            });
            
            $('form#submit_reply').submit(function(){
                if($.trim($('#selectable').val())==''){
                    alert('回复内容不能为空');
                    return false;
                }
            });
            
            $('.edit').click(function(){
                var content=$(this).parent('div').siblings("div.content-div").children('span.content-now').html();
                var root=$(this).parent('div').siblings("div.content-div");
                $(root).children('.content-now').css('display','none');
                $(root).children('.content').css('display','block');
                $(root).children('.content').html(content);
                $(this).parent('div.btn-select').html("<input type='submit' value='提交'/><input type='button' value='取消' onclick='document.location.reload();'/>");
            });
            
        });
    
       </script>
    </body>
</html>